package org.smart4j.framework.proxy;

import java.lang.reflect.Method;
import java.util.List;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * description: 代理管理器
 * @version v1.0
 * @author w
 * @date 2018年9月26日下午9:20:16
 */
public class ProxyManager {
	
	@SuppressWarnings("unchecked")
	public static <T> T createProxy(final Class<?> targetClass,final List<Proxy> proxyList){
		return (T) Enhancer.create(targetClass, new MethodInterceptor() {
			@Override
			public Object intercept(Object target, Method method, Object[] params, MethodProxy methodProxy) throws Throwable {
			
				return new ProxyChain(targetClass, target, method, methodProxy, params, proxyList).doProxyChain();
			}
		});
	}
}
